package map.android.baidu.carpool.page;

import map.android.baidu.carpool.utils.LogUtils;
import map.android.baidu.carpool.utils.NetworkUtils;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.baidu.lbs.place.page.PlaceBasePage;
import com.baidu.mapframework.widget.MProgressDialog;

/**
 * 拼车组件的NA页面基类
 */
public class CarpoolBasePage extends PlaceBasePage {

    protected FragmentActivity mActivity;
    protected boolean mIsDestroy;

    @Override
    public void onAttach(Activity activity) {
        mActivity = getActivity();
        super.onAttach(activity);
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mIsDestroy = false;
    }

    @Override
    public void onDetach() {
        LogUtils.d("LifeCycle", this.getClass().getName() + ".onDetach()");
        mActivity = null;
        super.onDetach();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        mIsDestroy = true;
    }

    @Override
    public int getDefaultRequestedOrientation() {
        return ActivityInfo.SCREEN_ORIENTATION_PORTRAIT;
    }

    @Override
    public boolean shouldOverrideRequestedOrientation() {
        return true;
    }

    @Override
    public boolean onBackPressed() {
        goBack();
        return true;
    }

    protected boolean checkNetworkStatus(boolean showToast) {
        return NetworkUtils.checkNetworkStatus(showToast);
    }

    protected void showLoadingDialog(boolean show, boolean cancelable) {
        if(mActivity != null)
            if (show) {
                MProgressDialog.show(mActivity, null);
            } else {
                MProgressDialog.dismiss();
    
            }
    }

    protected void showLoadingDialog(boolean show) {
        if(mActivity != null)
            if (show)
                MProgressDialog.show(mActivity, null);
            else
                MProgressDialog.dismiss();

    }

}
